package org.example.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.val;
import org.example.entity.Course;
import org.example.mapper.CourseMapper;
import org.example.service.CourseSerive;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

@Service
public class CourseSeriveImpl implements CourseSerive {
    @Autowired
    private CourseMapper courseMapper;

    @Override
    public Course getCourseById(int id) {
        Course courseById = courseMapper.getCourseById(id);
        return courseById;
    }

    @Override
    public PageInfo<Course> getCourses(Course course, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<Course> list = courseMapper.getCourses(course);
        PageInfo<Course> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public List<Course> selectCoursesById(int id) {
        List<Course> courses = courseMapper.selectCoursesById(id);
        return courses;
    }

    @Override
    public PageInfo<Course> getCoursesPage(Course course, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<Course> list = courseMapper.getCoursesPage(course);
        PageInfo<Course> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public Course getConsultants(int id) {
        Course consultants = courseMapper.getConsultants(id);
        return consultants;
    }

    @Override
    public List<Course> getConsultantsTag(int id) {
        List<Course> consultantsTag = courseMapper.getConsultantsTag(id);
        return consultantsTag;
    }

    @Override
    public PageInfo<Course> priceAsc(Course course, int page, int size) {
        PageHelper.startPage(page, size);
        List<Course> list = courseMapper.priceAsc(course);
        PageInfo<Course> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public PageInfo<Course> priceDesc(Course course, int page, int size) {
        PageHelper.startPage(page, size);
        List<Course> list = courseMapper.priceDesc(course);
        PageInfo<Course> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public List<Course> getCoursesByPriceRange(String priceRanges) {
        List<Course> courses = courseMapper.selectCoursesByPriceRange(priceRanges);
        return courses;
    }


}
